package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/AdminController")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("/adminOutLogin")
    public String adminOutLogin(HttpSession session){
        //手动注销session
        session.invalidate();
        return "redirect:/login.jsp";
    }

    @RequestMapping("/adminLogin")
    @ResponseBody
    public boolean adminLogin(String aname, String apwd, HttpSession session){
        Admin admin = adminService.findOneAdmin(aname, apwd);
        if (admin!=null){
            session.setAttribute("admin",admin);
            return true;
        }
        return false;
    }

    @RequestMapping("/findAllAdminLer")
    public PageA<Admin> findAllAdminLer(Integer page,Integer rows){
        return adminService.findAllAdmin(page, rows);
    }
}
